 let image=$('#image');
 let option
  = {
    aspectRation :1,
    preview:'.img-preview'
  }
  image.cropper(option);

  //点击上传图片
  $('button:contains("上传")').on('click',function () {
    $('#file').trigger('click');
  })

  //更换图片地址
  $('#file').on('change',function () {
    if( this.isDefaultNamespace.length>0){
      let fileObj=this.files[0];
      let url = URL.createObjectURL(fileObj);
      image.cropper('replace',url);
    }
  })

  //点击剪裁 提交到服务器
  $('button:contains("确定")').on('click',function () {
   let canvas= image.cropper('getCroppedCanvas',{width:30,height:30});

    let base64 = canvas.toDataURL();

    $.ajax({
      type:'POST',
      url:'/my/user/avatar',
      data:{avatar:base64},
success:function (res) {
  if(res.status===0){
    layer.msg(res.message);
    window.parent.getUserInfo();
  }
}
    })
  })